package demo1;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: 李白
 * @Created: 2024/4/26 12:00
 */
class B {
    public B() {
// do nothing
        func();
    }
    public void func() {
        System.out.println("B.func()");
    }
}
class D extends B {
    private int num = 1;
    @Override
    public void func() {
        System.out.println("D.func() " + num);
    }
}
public class Test {
    public static void main(String[] args) {
        D d = new D();
    }



    public static void main1(String[] args) {
        Shape[] shapes = {new Cycle(),new Rect(),new Flower(),new Rect()};
        for (Shape shape : shapes) {//其中，冒号的前方只是用一个未知数接替数组一个个传来的值，主要的还是花括号的代码
            shape.draw();
        }
       /* Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"rect","cycle","flower","rect"};
        for (String shape:shapes) {
            if(shape.equals("rect")){
                rect.draw();
            }else if(shape.equals("cycle")){
                cycle.draw();
            }else {
                flower.draw();
            }
        }*/
    }


}
class Shape{
    public void draw(){
        System.out.println("形状");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("圆形");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("花");
    }
}
